package com.faeple.conversation.dao.sqlmap;

import java.util.HashMap;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.faeple.conversation.dao.ConversationDao;
import com.faeple.conversation.entity.ConversationDto;
import com.faeple.conversation.entity.ConversationReplyDto;

@Repository
public class SqlMapConversationDao implements ConversationDao {

	@Autowired
	private SqlSession sqlSession;
	
	@Override
	public List<ConversationDto> getConversationList(String idx) {
		return sqlSession.selectList("ConversationMapper.getConversationList", idx);
	}

	@Override
	public int sendMessage(HashMap<String, String> param) {
		return sqlSession.insert("ConversationMapper.sendMessage", param);
	}

	@Override
	public String isConversation(HashMap<String, String> param) {
		return sqlSession.selectOne("ConversationMapper.isConversation", param);
	}

	@Override
	public int createConversation(HashMap<String, String> param) {
		return sqlSession.insert("ConversationMapper.createConversation", param);
	}

	@Override
	public int getNewMessageCount(String idx) {
		return sqlSession.selectOne("ConversationMapper.getNewMessageCount", idx);
	}

	@Override
	public List<ConversationReplyDto> getMessages(HashMap<String, String> param) {
		return sqlSession.selectList("ConversationMapper.getMessages", param);
	}

	@Override
	public int setIsRead(HashMap<String, String> param) {
		return sqlSession.update("ConversationMapper.setIsRead", param);
	}

	@Override
	public int deleteMessage(HashMap<String, String> param) {
		return sqlSession.update("ConversationMapper.deleteMessage", param);
	}

	@Override
	public int changeDeleteState(HashMap<String, String> param) {
		return sqlSession.update("ConversationMapper.changeDeleteState", param);
	}

	@Override
	public String getMemberIdx(String id) {
		return sqlSession.selectOne("ConversationMapper.getMemberIdx", id);
	}
}
